// pages/joinPsnPage/joinPsnPage.js
var config = require('../util/config.js');
var $ = require('../util/commit.js');
var page = 1;
var pageMore = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    psnData:[{
      id:495,
      url:'https://app.xingxue.vip/icon/icon49.png',
      name:'成都小甜甜',
      school:'南邮大学'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
    let that=this;
    let param=JSON.parse(options.data);
    that.setData({
      param: param,
    });
    that.loadData();
  },
  loadData:function(e){
    wx.showLoading({
      title: '加载中...',
    });
    let that=this;
    $.POST({
      url:'caCSRCUL',
    
      data:{
        caid:that.data.param.id,
        page: 1,
      }
    },function(e){
      that.setData({
        psnData:e.data
      });
      page=1;
      pageMore = true;
      wx.hideLoading();
    },function(e){
      page = 1;
      pageMore = true;
      wx.hideLoading();
    });
  },
  loadMoreData: function (e) {
    let that = this;
   
    if (pageMore){
      wx.showLoading({
        title: '加载中...',
      });
      pageMore=false;
      page++;
      $.POST({
        url: 'caCSRCUL',
       
        data: {
          caid: that.data.param.id,
          page: page,
        }
      }, function (e) {
        let newPsnData = that.data.psnData.concat(e.data);
   
        that.setData({
          psnData: newPsnData
        });
        pageMore = true;
        wx.hideLoading();
      }, function (e) { 
        if (page>1){
          page--;
        }
        pageMore = true;
        wx.hideLoading();
      });
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh');
    this.loadData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 跳转到行学
  ToPsnPage:function(e){
    wx.navigateToMiniProgram({
      appId: config.Config.XXAPPId,
      path: 'pages/home/home?Type=AAJoinPsnPage&id=' + e.currentTarget.dataset.id,
      envVersion: 'release',
      extraData:{
        Type:'AAJoinPsnPage'
      },
      success(res) {
        // 打开成功
      }
    })
  }
})